package com.easyfile.easyfilemaster.config;

import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.DES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 常规配置类
 * @author chenpeman
 * @date 2022年05月29日 13:23
 */
@Configuration
public class NormalConfig {
    /**对称加密密匙*/
    public static final String KEY="chenpeman";

    /**
     *创建对称加密加密器
     *
     * @return the symmetric crypto
     */
    @Bean
    public DES getAes(){
        return SecureUtil.des(
                SecureUtil.generateKey(SymmetricAlgorithm.DES.getValue(), KEY.getBytes()).getEncoded());
    }

    /**
     * 发送短信验证码线程池
     *
     * @return the thread pool executor
     */
    @Bean("smsThreadPool")
    public ThreadPoolExecutor smsThreadPool(){
        return new ThreadPoolExecutor(
                2,
                4,
                1,
                TimeUnit.MINUTES,
                new ArrayBlockingQueue<>(100)
                );
    }
}
